import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','admin']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  

]
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' , roles:['hr','manger'] }
    }]
  },
  // 员工信息
  {
    path: '/employee',
    component: Layout,
    redirect: '/employee/index',
    alwaysShow: true, // will always show the root menu
    name: 'employee',
    meta: {
      title: '员工信息',
      icon: 'user',
      roles:['hr','admin','manger']
    },
    children: [
      //员工合同
      {
        path: 'index',
        component: () => import('@/views/document/index'),
        name: 'employee',
        meta: {
          title: '员工合同',
          icon: 'el-icon-notebook-1',
          roles:['hr','admin','manger']
        }
      },
      //每个员工的详细信息
      {
        path:'onself',
        component:()=>import('@/views/document/oneself'),
        name:'oneself',
        meta:{
          title:'员工详细信息',
          roles:['hr','admin','manger']
        },
        hidden:true

      },
      //员工处分记录
      {
        path: 'punishment',
        component: () => import('@/views/document/punishment'),
        name: 'punishment',
        meta: {
          title: '员工处分记录',
          icon: 'el-icon-warning',
          roles:['hr','admin','manger']
        }
      },
      //员工培训计划
      {
        path:'train',
        component:()=>import('@/views/train/index'),
        name:'Train',
        meta:{
          title:'员工培训计划',
          icon:'el-icon-date',
          roles:['admin','hr','manger']
        }
      },
      {
        path:'addTrain',
        component:()=>import('@/views/train/add'),
        name:'AddTrain',
        meta:{
          title:'新建培训',
          roles:['admin','hr','manger']
        },
        hidden:true    
      },

      {
        path:'modifyTrain',
        component:()=>import('@/views/train/modify'),
        name:'ModifyTrain',
        meta:{
          title:'修改培训信息',
          roles:['admin','hr','manger']
        },
        hidden:true
      },{
        path:'attendence',
        component:()=>import('@/views/document/attendence'),
        name:'Attendence',
        meta:{
          title:'出勤管理',
          roles:['admin','hr','manger'],
          icon:'el-icon-alarm-clock'
        }
      }
    ]
  },

  //背调系统
  {
    path: '/background',
    component: Layout,
    redirect: '/background/index',
    alwaysShow: true, // will always show the root menu
    name: 'backgroud',
    meta: {
      title: '背调系统',
      icon: 'el-icon-s-check',
      roles:['admin','hr','manger']
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/background/index'),
        name: 'backgroundMange',
        meta: {
          title: '背调管理',
          icon: 'el-icon-office-building',
          roles:['admin','hr','manger']
        }
      },{
        path:'oneself',
        component:()=> import('@/views/background/oneself'),
        name:"BackgroundOnself",
        meta:{
          title:'个人背景信息',
          roles:['admin','hr','manger']
        },
        hidden:true
      }
    ]
  },
  {
    path: '/department',
    component: Layout,
    redirect: '/department/index',
    alwaysShow: true, // will always show the root menu
    name: 'Department',
    meta: {
      title: '部门管理',
      icon: 'el-icon-office-building',
      roles:['admin']
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/department/index'),
        name: 'Departmentson',
        meta: {
          title: '部门管理',
          icon: 'el-icon-office-building',
          roles:['admin']
         
        }
      }

    ]
  },
  //系统管理
  {
    path: '/system',
    component: Layout,
    redirect: '/system/index',
    alwaysShow: true, // will always show the root menu
    name: 'system',
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-tools',
      roles:['admin','hr','manger']
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/system/index'),
        name: 'modify',
        meta: {
          title: '密码修改',
          icon: 'el-icon-office-building',
          roles:['admin','hr','manger'] 
        }
      }
    ]
  }, 
 
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}


export default router
